#include <iostream>
#include <algorithm>
#include<vector>
#include <set>
#include <sstream>
#include <map>
using namespace std;

int judge(char a, char b) {
	if (a == b) {
		return 0;
	}
	if (a == 'C') {
		if (b == 'J') {
			return 1;
		} else {
			return -1;
		}
	} else if (a == 'J') {
		if (b == 'B') {
			return 1;
		} else {
			return -1;
		}
	} else if (a == 'B') {
		if (b == 'C') {
			return 1;
		} else {
			return -1;
		}
	}
}

bool cmp(pair<char, int> vc1, pair<char, int> vc2) {
	
	if (vc1.second != vc2.second) {
		return vc1.second > vc2.second;
	} else
	{
		return vc1.first < vc2.first;
	}

}

int main() {

	int n;
	int countA[3] = {0, 0, 0};
	int countB[3] = {0, 0, 0};
	map<char, int> mp1;
	mp1['C'] = 0;
	mp1['J'] = 0;
	mp1['B'] = 0;
	map<char, int> mp2;
	mp2['C'] = 0;
	mp2['J'] = 0;
	mp2['B'] = 0;

	scanf("%d", &n);
	char a, b;
	int res;
	for (int i = 0; i < n; i++) {
		getchar();
		scanf("%c %c", &a, &b);
		res = judge(a, b);
		if (res == 0) {
			countA[1]++;
			countB[1]++;
		} else if (res == 1) {
			mp1[a]++;
			countA[0]++;
			countB[2]++;
		} else if (res == -1) {
			mp2[b]++;
			countA[2]++;
			countB[0]++;
		}
	}

	printf("%d %d %d\n", countA[0], countA[1], countA[2]);
	printf("%d %d %d\n", countB[0], countB[1], countB[2]);

	vector<pair<char, int>> tmp1(mp1.begin(), mp1.end());
	vector<pair<char, int>> tmp2(mp2.begin(), mp2.end());



	sort(tmp1.begin(), tmp1.end(), cmp);
	sort(tmp1.begin(), tmp1.end(), cmp);

	printf("%c %c", tmp1[0].first, tmp2[0].first);


    return 0;
}	